//
//  PostNumVC.m
//  renyikan
//
//  Created by Steven on 2019/7/16.
//  Copyright © 2019 Steven. All rights reserved.
//

#import "PostNumVC.h"

@interface PostNumVC ()
@property(nonatomic,weak)IBOutlet UITextField *inputTF;

@property (weak, nonatomic) IBOutlet UILabel *countryLabel;

@property (weak, nonatomic) IBOutlet UILabel *provinceLabel;
@property (weak, nonatomic) IBOutlet UILabel *cityLabel;

@property (weak, nonatomic) IBOutlet UILabel *postNumLabel;

@property (weak, nonatomic) IBOutlet UILabel *addressLabel
;
@end

@implementation PostNumVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (IBAction)searchAction:(UIButton *)sender{
    [self.view endEditing:YES];
    
    if (self.inputTF.text.length == 0) {
        [MBProgressHUD showError:@"请输入邮政编码！"];
        return;
    }
    
    __weak typeof(self) weakSelf = self;
    [JFNetworkingManager requestWithURLString:[NSString stringWithFormat:@"http://v.juhe.cn/postcode/query?key=934747be989811c9175a6457ab61ab32&postcode=%@",self.inputTF.text ] parameters:nil type:HttpRequestTypePost view:self.view success:^(id responseObject) {
        
        weakSelf.countryLabel.hidden = false;
        weakSelf.countryLabel.text = responseObject[@"result"][@"District"];
        
        weakSelf.provinceLabel.hidden = false;
        weakSelf.provinceLabel.text = responseObject[@"result"][@"Province"];
        
        weakSelf.postNumLabel.hidden = false;
        weakSelf.postNumLabel.text = responseObject[@"result"][@"PostNumber"];
        
        weakSelf.addressLabel.hidden = false;
        weakSelf.addressLabel.text = responseObject[@"result"][@"Address"];
        
        weakSelf.cityLabel.hidden = false;
        weakSelf.cityLabel.text = responseObject[@"result"][@"City"];
        
    } failure:^(NSError *error) {
        
    }];
    
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self.view endEditing:YES];
}
@end
